﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ColumnsInformation
{
    public class ColumnInfo
    {
        public string Name;
        public string Type;
        public string Default;
        public bool IsNullable;
    }
    public class ColumnsInfo : ICloneable
    {
        public string ColumnsWithPrimaryKey;
        private List<ColumnInfo> columns;
        public ColumnsInfo()
        {
            columns = new List<ColumnInfo>();             
        }
        public ColumnInfo this[int index]
        {
            get
            {
                if (index < columns.Count)
                    return columns[index];
                else
                    throw new IndexOutOfRangeException();
            }
            private set { ; }
        }     
        public string GetColumnType(string columnName)
        {
            try
            {
                foreach (var column in columns)
                    if (column.Name == columnName)
                        return column.Type;
                return null;
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            catch (NullReferenceException ex)
            {
                throw ex;
            }
        }
        public int Count
        {
            get
            {
                return columns.Count;
            }
            private set { ;}
        }
        public void Add(ColumnInfo info)
        {
            columns.Add(info);
        }
        public IEnumerator<ColumnInfo> GetEnumerator()
        {
            for (int i = 0; i < columns.Count; i++)
                yield return columns[i];
        }
        public object Clone()
        {
            ColumnsInfo colInfo = new ColumnsInfo()
            {
                columns = new List<ColumnInfo>(),
                ColumnsWithPrimaryKey = this.ColumnsWithPrimaryKey                
            };
            foreach (var columInfo in this.columns)
                colInfo.columns.Add(columInfo);
            return colInfo;
        }
    }
}
